﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;

namespace Axial.Tests
{
	[TestFixture]
	[JSSafe]
	public class CSharpTests : TestBase
	{
		[Test]
		public void ActionTest()
		{
			VerifyMethodOutput("Action",
@"this.TakeAnAction(function()
{
	this.DoNothing();
}
);");
		}
		public void Action()
		{
			TakeAnAction(() => DoNothing());
		}

		[Test]
		public void ActionWithParamTest()
		{
			VerifyMethodOutput("ActionWithParam",
@"this.TakeAnAction(function(arg0)
{
	this.DoNothing(arg0);
}
);");
		}
		public void ActionWithParam()
		{
			TakeAnAction((a) => DoNothing(a));
		}

		public void TakeAnAction(Action act)
		{
		}
		public void TakeAnAction(Action<int> act)
		{
		}
		public void DoNothing()
		{
		}
		public void DoNothing(int a)
		{
		}

		[Test]
		public void TernaryOperatorTest()
		{
			VerifyMethodOutput("TernaryOperator", 
@"a = b == 1 ? b : c;
a = a + 1;");
		}
		public void TernaryOperator()
		{
			int a;
			int b = 1;
			int c = 2;
			a = b == 1 ? b : c;
			a++;
		}

		[Test]
		public void TernaryReturnTest()
		{
			VerifyMethodOutput("TernaryReturn",
@"a = b == 1 ? b : c;
return a;");
		}
		public int TernaryReturn()
		{
			int a;
			int b = 1;
			int c = 2;
			a = b == 1 ? b : c;
			return a;
		}

		[Test]
		public void TernaryInIfTest()
		{
			VerifyMethodOutput("TernaryInIf",
@"if ((a == 1 ? a : b) == 3)
	b = 1;");
		}
		public void TernaryInIf()
		{
			int a = 1;
			int b = 2;
			if ((a == 1 ? a : b) == 3)
				b = 1;
		}
	}
}
